
use "Data/Census w-restrictions.dta", clear

gen ltd_iss_real = ltd_iss_all_other

keep id year type_code ltd_iss_all_other ltd_iss_private_purp total_ltd_issued total_interest_on_debt total_capital_outlays total_taxes ltd_iss_real total_cash___securities  ///
general_expenditure  gen_rev_own_sources  total_current_oper  emp_ret_benefit_paymts  total_salaries___wages  total_expenditure  total_current_expend  ///
total_rev_own_sources  total_educ_total_exp  total_debt_outstanding  population fyend


replace ltd_iss_all_other = 0 if ltd_iss_all_other == .
replace total_ltd_issued = 0 if total_ltd_issued == .
replace ltd_iss_real = 0 if ltd_iss_real == .

gen log_capital = log(total_capital_outlays + 1)
gen log_expend = log(total_expenditure + 1)
gen log_salaries = log(total_salaries___wages + 1)
gen log_interest = log(total_interest_on_debt + 1)
gen log_tax = log(total_taxes)
gen log_issued = log(total_ltd_issued)
gen log_debt = log(ltd_iss_real + 1)
gen log_cash = log(total_cash___securities + 1)
gen log_rev_own = log(total_rev_own_sources)
gen log_curr_oper = log(total_current_oper + 1)
gen log_tdo = log(total_debt_outstanding + 1)

foreach var in log_interest ltd_iss_all_other {
gen l2_`var' = l2.`var'
gen l_`var' = l.`var'
gen f_`var' = f.`var'
gen f2_`var' = f2.`var'
gen f3_`var' = f3.`var'
gen f4_`var' = f4.`var'
}

keep if ltd_iss_all_other == total_ltd_issued

preserve

** Columns 1 and 2

gen diff_int = f_log_interest - log_interest
keep if diff_int != .
drop if ltd_iss_all_other <= 10000
keep if (year == 2010 & fyend <= 630) | (year == 2011 & fyend > 630) | year == 2007
keep if year == 2010 | year == 2011 | (year == 2007 & ltd_iss_all_other <= 30000 & fyend <= 630 & f3.ltd_iss_all_other <= 30000) | ///
(year == 2007 & ltd_iss_all_other <= 30000 & fyend > 630 & f4.ltd_iss_all_other <= 30000) | ///
(year == 2007 & ltd_iss_all_other > 30000 & fyend <= 630 & f3.ltd_iss_all_other > 30000) | ///
(year == 2007 & ltd_iss_all_other > 30000 & fyend > 630 & f4.ltd_iss_all_other > 30000) 

by id: egen count = count(id)
keep if count == 2

gen treat = ltd_iss_all_other <= 30000
gen post = (year == 2010 | year == 2011)
gen treat_post = treat * post

reg diff_int treat_post treat post, cluster(id)
outreg2 using "Table 4", keep(treat_post) dec(3) nocons nor2 replace
reg diff_int treat_post treat post log_issued log_expend log_tdo log_rev_own i.type_code, cluster(id)
outreg2 using "Table 4", keep(treat_post) dec(3) nocons nor2 append

** Columns 3 and 4

restore
gen diff_int = f_log_interest - l_log_interest
keep if diff_int != .
drop if ltd_iss_all_other <= 10000
keep if (year == 2010 & fyend <= 630) | (year == 2011 & fyend > 630) | year == 2007
keep if year == 2010 | year == 2011 | (year == 2007 & ltd_iss_all_other <= 30000 & fyend <= 630 & f3.ltd_iss_all_other <= 30000) | ///
(year == 2007 & ltd_iss_all_other <= 30000 & fyend > 630 & f4.ltd_iss_all_other <= 30000) | ///
(year == 2007 & ltd_iss_all_other > 30000 & fyend <= 630 & f3.ltd_iss_all_other > 30000) | ///
(year == 2007 & ltd_iss_all_other > 30000 & fyend > 630 & f4.ltd_iss_all_other > 30000) 

by id: egen count = count(id)
keep if count == 2

gen treat = ltd_iss_all_other <= 30000
gen post = (year == 2010 | year == 2011)
gen treat_post = treat * post

reg diff_int treat_post treat post, cluster(id)
outreg2 using "Table 4", keep(treat_post) dec(3) nocons nor2 append
reg diff_int treat_post treat post log_issued log_expend log_tdo log_rev_own i.type_code, cluster(id)
outreg2 using "Table 4", keep(treat_post) dec(3) nocons nor2 append

